<?php

	echo "
	<tr align='center' height='20' class='Normal'>
		<td>&nbsp;</td>
        <td align='left' width='230'><b>Product</b></td>
		<td align='center' width='30'><b>qty</b></td>
		<td align='center' width='60'><b>Unit Price ".CURRENCY."</b></td>
		<td align='center' width='90'><b>Net Price ".CURRENCY."</b></td>
		<td align='center' width='80'><b>VAT</b></td>
		<td align='right' width='120'><b>Total ".CURRENCY."</b></td>
		<td>&nbsp;</td>
    </tr>
	";

	if ($intOrderHeaderID){ 
	    include (MODULE . "/action/qrySelectOrderDetails$SHOP_TYPE");
	}

	if(!$myrow["ID"]==""){
	     do {
		 	
		echo "
		<tr align='right' bgcolor=\"".switch_background($boBG)."\" class='Normal'>
			<td>";
			 if($intOrderStatus != '5'){
			 	echo "
					<a href='" . ScreenURL("EnterOrderDetails",array('intOrderDetailsID'=>$myrow["ID"]) ) . "'>
			        <img src='./images".SITE_SUFFIX."/update.gif' border='0' alt='Update' align='middle'></a><br/>
				";
			}else{
				echo "&nbsp;";
			}
			echo "
			</td>
	 		<td align='left' height='40'>";
				
					if ($myrow["QuantityPerUnit"]>1){
						echo $myrow["QuantityPerUnit"]."&nbsp;";
					}
					
				echo "<span class='Small'>".$myrow["Product"];
				
	     			if($myrow["Colour"]){
						echo "&nbsp; Colour: ".$myrow["Colour"];
					}
								
					if($myrow["Size"]){
						echo "&nbsp;Size: ".$myrow["Size"];
					}
				
					if($myrow["SupplierProductID"]){
						echo "<br/>(".$myrow["SupplierProductID"].")";
					}
				echo "
				</span>";
					
			echo "
			</td>
			<td>".$myrow["Quantity"]."</td>
			<td>".number_format($myrow["NetPrice"], 2, '.', '')."</td>
	        <td>".number_format($myrow["NetTotal"], 2, '.', '')."</td>
	        <td>".number_format($myrow["VatPayable"], 2, '.', '')."</td>
			<td>
				".number_format($myrow["Amount"], 2, '.', '')."
			</td>
			<td>";
				echo "						
					<a href='".ScreenURL("EmailCustomer",array('intPromotionalItem'=>$myrow["PromotionalItem"],'intCustomerID'=>$intCustomerID,'strSupplierProduct'=>$myrow["SupplierProductID"],'intSupplierID'=>$myrow[Supplier],'intQuantity'=>$myrow["QuantityPerUnit"],'intOrderHeaderID'=>$intOrderHeaderID,'intOrderDetailsID'=>$myrow["ID"]))."'>
						<img src='./images".SITE_SUFFIX."/checkstock.gif' border='0' alt='check stock' align='middle'>
					</a>
					<br/>";
				
				 if($intOrderStatus != '5'){
				 	echo "
					<a href=\"" . ScreenURL("DisplayOrderHeader",array('intOrderHeaderID'=>$intOrderHeaderID,'intOrderDetailsID'=>$myrow["ID"],'ACTION'=>"qryDeleteOrderDetails") ) . "\"
					onclick=\"return confirmLink(this, 'Delete Item From Order');\">
					<img src='./images".SITE_SUFFIX."/delete.gif' border='0' alt='Delete' align='middle'></a>
					<br/>";
				 	
				 if ($intOrderStatus != '6'){
						echo "						
						<a href='".ScreenURL("DisplayOrderHeader",array('ACTION'=>'actOrderRefund','intOrderHeaderID'=>$intOrderHeaderID,'intOrderDetailsID'=>$myrow["ID"]))."' onclick=\"return confirmLink(this, 'Refund Item From Order');\">
							<img src='./images".SITE_SUFFIX."/refund.gif' border='0' alt='refund item' align='middle'>
						</a>
						<br/>";
					}
				}
				
				
echo "
			</td>
	    </tr>";
		
		$boBG = -1 - $boBG; //alternate $boBG values from -1 and 0
		$intTotal = number_format($intTotal + $myrow["Amount"], 2, '.', '');
		$intVatPayableTotal = number_format($intVatPayableTotal + $myrow["VatPayable"], 2, '.', '');
		$intNetTotalTotal = number_format($intNetTotalTotal + $myrow["NetTotal"], 2, '.', '');
		$intVATRate = $myrow["VatRate"];

		
	} while ($myrow = mysql_fetch_array($result));
	

	
    echo "
		<tr class='Normal'>
	        <td colspan='1' align='left'  height='20'>&nbsp;</td>
			<td>Carriage</td>";
			
				if ($intOrderCarriage !== "0.00"){
					if($SHOP_TYPE == "Trade"){
						$intNetCarriage = number_format($intOrderCarriage, 2, '.', '');
						$intVATCarriage = number_format(($intOrderCarriage * ($intVATRate/100)), 2, '.', '');
						$intTotalCarriage = number_format(($intOrderCarriage + $intVATCarriage), 2, '.', '');
						$intTotal = $intTotal + $intTotalCarriage;
					}else{
						$intNetCarriage = number_format($intOrderCarriage / (($intVATRate/100)+1), 2, '.', '');
						$intVATCarriage = number_format(($intOrderCarriage - ($intOrderCarriage / (($intVATRate/100)+1))), 2, '.', '');
						$intTotalCarriage = number_format($intOrderCarriage, 2, '.', '');
						$intTotal = $intTotal + $intTotalCarriage;
					}
					
					echo "	<td colspan='3' align='right'>".$intNetCarriage."</td>
							<td align='right'>$intVATCarriage</td>
							<td  align='right'>".$intTotalCarriage."</td>";
				}else{
					$intNetCarriage = '0';
					$intVATCarriage = '0';
					$intTotalCarriage = '0';
					 echo "<td colspan='5' align='right' class='Small'>Included</td>";
				}
			
	
	echo "
			<td>
				&nbsp;
			</td>
	    </tr>
	
		<tr class='Normal'>
			<td>&nbsp;</td>
	 		<td colspan='3'  height='20'><b>Total</b></td>
			<td align='right'><b>".CURRENCY.number_format($intNetTotalTotal + $intNetCarriage, 2, '.', '')."</b></td>
			<td align='right'><b>".CURRENCY.number_format($intVatPayableTotal + $intVATCarriage, 2, '.', '')."</b></td>
			<td align='right'>
				<b>".CURRENCY.number_format($intTotal, 2, '.', '')."</b>
			</td>
			<td>";
				 if($intOrderStatus != '5'){
				 	echo "
						<a href='" . ScreenURL("EnterOrderDetails",array('intOrderHeaderID'=>$intOrderHeaderID) ) . "'>
				        <img src='./images".SITE_SUFFIX."/additem.gif' border='0' alt='add item to order' align='middle'></a><br/>
					";
				}else{
					echo "&nbsp;";
				}
echo "
			</td>
	    </tr>
	"; 
	}else{
		echo "
	     <tr class='MandatoryRed'><br/>
	         <td colspan='8'>
	             This Order is incomplete.
	         </td>
	     </tr>
		";
	}
	
?>